<?php 

// 详情页控制器
class DetailsController extends CommonController{

// 商品详情页显示
   public function index(){
     // p($_SESSION);
     
   	 $goods_id=Q('get.goods_id',0,'intval');
     session('goods_id',$goods_id);
     $cid=Q('get.cat_id',0,'intval');
     // 调用面包屑方法 
      $this->crumb($cid);

     // 商品显示
     $detail=M()->join('__goods__ g join __detail__ d on g.goods_id=d.gid ')->where("goods_id={$goods_id}")->find();
    $this->assign('detail',$detail);
    
     // 商品属性显示
      $goodsAttr=K('GoodsAttr')->where("gid={$goods_id}")->all();
    
   
        

 // 图集显示
 $big=explode(',',$detail['big']);
  $this->assign('big',$big);
   
// 一周排行榜
   $top=K('Goods')->where("click>10 and cat_id={$cid} ")->order('add_time desc')->limit('0,5')->all();
    $this->assign('top',$top);

  // 买了还买
    $buyed=K('Goods')->where("cat_id={$cid} and is_hot=1")->limit('0,3')->all();
    $this->assign('buyed',$buyed);

// p($big);die;
     // p($conBig);die;

  // 获得规格
   $tid=$_GET['type_id'];

  $attr=K('Attribute')->where("class=1 and type_id={$tid}")->all();

  foreach($attr as $k=>$v){
    $attr[$k]['spec']=K('GoodsAttr')->where("gid={$goods_id} and attr_id={$v['attr_id']}")->all();

  } 
  $this->assign('attr',$attr);
  // p($attr);die;

     
    


    $this->display();




   }





// 商品颜色和尺寸异步处理
public function ajaxGetSpec(){
  if(!IS_AJAX) $this->error('非法请求');
    $id=Q('post.id');
 
    
   // p($id);
    $gid = Q('post.gid',0,'intval');
  $GoodsList = K('Shoplist')->where("gid={$goods_id} AND combine='{$id}'")->find();
   // p($GoodsList);
    //判断是否存在库存
    if($GoodsList){
      $inv= intval($GoodsList['inventory']);
      $this->ajax($inv);
    }
    $this->ajax(0);


}






}















 ?>